<template>
  <div>

    <el-form
        ref="form"
        :model="form"
        label-width="80px"
        style="
        position: absolute;
        margin-left: 200px;
        margin-top: 10px;
        width: 400px;
      "
    >
      <h1 style="text-align: center; margin-top: 0px; margin-bottom: 50px;">药房</h1>
      <el-form-item label="病房编号">
        <el-input v-model="form.wardCode"></el-input>
      </el-form-item>
      <el-form-item label="房位数量">
        <el-input-number v-model="form.wardNum"></el-input-number>
      </el-form-item>
      <el-form-item label="负责人">
        <el-select v-model="form.doctorName">
          <el-option v-for="doctorName in form.doctorName_list" :label=doctorName.name
                     :value=doctorName.id></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="病房类型">
        <el-select v-model="form.wardType" placeholder="请选择病房类型">
          <el-option label="普通病房" value="1"></el-option>
          <el-option label="高级病房" value="2"></el-option>
          <el-option label="隔离病房" value="3"></el-option>
          <el-option label="重症监护室" value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="createRoom">立即创建</el-button>
        <el-button type="danger" plain @click="resetForm('formInline')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import router from "../../router";

export default {
  name: "NewRoom",
  data() {
    return {
      form: {
        wardCode: "",
        wardNum: "",
        wardType: "",
        doctorName_list: [],
        doctorName: "",
      },
    };
  },
  created() {
    this.$axios.get(this.$settings.BASE_URL + 'patient/doctorName/').then(response => {
      this.form.doctorName_list = response.data
    })
  },
  methods: {
    createRoom() {
      //axios新建科室请求
      console.log('我进来啦')
      this.$axios.post(this.$settings.BASE_URL + 'patient/createRoom/', {
        ward_code: this.form.wardCode,
        ward_number: this.form.wardNum,
        ward_type: this.form.wardType,
        doctor: this.form.doctorName,
      }).then((Response) => {
        this.$message({
          message: "新建" + this.form.wardCode + "病房成功",
          type: 'success',
          duration: 1000
        })
        window.setTimeout(function () {
          router.push({path: '/index/inWard'})
        }, 2000)
      }).catch((error) => {
        console.error(error);
      });
    },
    resetForm(formName) {
      location.reload();
    },
  },
}
</script>

<style scoped>

</style>